package com.xjlsoft.weather.dto;

import com.xjlsoft.weather.enums.ResultCodeEnum;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * 第三方接口返回结果
 */
@ApiModel(value = "Response对象", description = "json")
public class ResultEntity {
	
	@ApiModelProperty(value = "结果编码")
    private String code;//结果编码
	
	@ApiModelProperty(value = "结果信息")
    private String msg;//结果信息
	
	@ApiModelProperty(value = "返回数据信息")
    private Object data;//返回数据信息
    
	@ApiModelProperty(value = "成功标识")
    private boolean success; //成功标识
    
    
    public String getEchoCode() {
        return code;
    }

    public void setEchoCode(String echoCode) {
        this.code = echoCode;
    }

    public String getEchoDes() {
        return msg;
    }

    public void setEchoDes(String echoDes) {
        this.msg = echoDes;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
    
    

    public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public boolean getSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	
	/**
	 * 返回 结果和消息 
	 * */
    public ResultEntity(ResultCodeEnum resultCodeEnum) {
        this.code = resultCodeEnum.getValue();
        this.msg = resultCodeEnum.getMessage();
    }
    
    public ResultEntity(Object object) {
    	this.data = object;
    }

    public ResultEntity(ResultCodeEnum resultCodeEnum, Object object) {
        this.code = resultCodeEnum.getValue();
        this.msg = resultCodeEnum.getMessage();
        this.data = object;
    }

    public ResultEntity(ResultCodeEnum resultCodeEnum, Object data,boolean successFlag) {
        this.code = resultCodeEnum.getValue();
        this.msg = resultCodeEnum.getMessage();
        this.data = data;
        this.success=successFlag;
    }
    
    public ResultEntity(ResultCodeEnum resultCodeEnum, String message,Object data,boolean successFlag) {
        this.code = resultCodeEnum.getValue();
        this.msg = message;
        this.data = data;
        this.success=successFlag;
    }

  

	public static ResultEntity  format(ResultCodeEnum resultCodeEnum, String... preciseInfo){
        ResultEntity resultEntity =  new ResultEntity(resultCodeEnum);
        if (preciseInfo.length > 0) {
            resultEntity.msg = String.format(resultCodeEnum.getMessage(), preciseInfo);
        }
        return resultEntity;
    }

}
